﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NapCardOnline.Models;
using NapCardOnline.ViewModel;
using PagedList;

namespace NapCardOnline.Controllers
{
    public class HistoryController : Controller
    {
        HistoryViewModels historyViewModels = new HistoryViewModels();
        NapCardOnlineEntities db=new NapCardOnlineEntities();
        //
        // GET: /History/

        public ActionResult Index()
        {
            historyViewModels.TransferFundList = db.TransferFunds.ToList();
            historyViewModels.PaymentList = db.Payments.ToList();
            return View(historyViewModels);
        }

        public ActionResult LoadTransferFund(int? page)
        {
            User objUser = Session["User"] as User;
            var transferFunds =
                db.TransferFunds.Include("TransferFundType").Include("User").Include("Status").Where(t => t.FK_ToUserID == objUser.UserID || t.FK_FromUserID == objUser.UserID).
                    OrderByDescending(t => t.TransferFundDate);
            var pageNumber = page ?? 1;
            var onePageOfTransferFund = transferFunds.ToPagedList(pageNumber, 10);
            ViewBag.OnePageOfTransferFund = onePageOfTransferFund;

            ViewBag.CountTransfer = transferFunds.Count();
            ViewBag.TotalAmount = transferFunds.Sum(t => t.TransferFundAmount);
            ViewBag.TotalCommisionAmount = transferFunds.Sum(t => t.TransferFundCommissionAmount);
            return Json(new
                            {
                               success=onePageOfTransferFund,
                            });
        }

        //public ActionResult LoadPayment()
        //{

        //}
    }
}
